package yourapp.expense.service;

import yourapp.expense.dao.ExpenseDAO;
import yourapp.expense.dto.StatisticsDTO;
import yourapp.expense.entity.Expense;

import java.sql.Date;
import java.util.List;

public class ExpenseService {

  private ExpenseDAO expenseDAO;
  private QueryService queryService = new QueryService();
  public ExpenseService() {
    // 初始化 ExpenseDAO
    this.expenseDAO = new ExpenseDAO();
  }

  /**
   * 添加一个新的支出记录到数据库
   * @param expense 要添加的支出记录对象
   */
  public void addExpense(Expense expense) {
    // 调用 ExpenseDAO 的方法插入支出记录
    expenseDAO.insertExpense(expense);
  }
  //返回最近支出记录8条
  public List<Expense> getRecentExpenses() {
    return expenseDAO.fetchRecentExpensesFromView();
  }

  // ExpenseService.java 新增方法

  public void deleteExpense(int expenseId) {
    expenseDAO.deleteExpense(expenseId);
  }
  public Expense getExpenseById(int expenseId){
    return expenseDAO.getExpenseById(expenseId);
  }

  // ExpenseService.java 新增方法

  public Expense getViewById(int expenseId) {
    return expenseDAO.getViewById(expenseId);
  }

  public void updateExpenseField(Expense expense, int fieldChoice) {
    switch (fieldChoice) {
      case 1:
        expenseDAO.updateAmount(expense);
        break;
      case 2:
        expenseDAO.updateExpenseDate(expense);
        break;
      case 3:
        expenseDAO.updateDescription(expense);
        break;
      case 4:
        expenseDAO.updatePaymentAppCategory(expense);
        break;
      case 5:
        expenseDAO.updateShoppingAppCategory(expense);
        break;
      case 6:
        expenseDAO.updatePurposeCategory(expense);
        break;
      default:
        System.out.println("无效的字段选择");
    }
  }

}